﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Draco.OWF.RT;
using System.Xml;

namespace Draco.OWF.Acticity.General
{
    public class InvokerActivity : AbstractActivity
    {
        private const String Prop_InvokObjectType = "InvokObjectType";
        private const String Prop_InvokObjectRef = "InvokObjectRef";
        private const String Prop_InvokeMethod = "InvokeMethod";
        private String m_InvokObjectType;
        private String m_InvokObjectRef;
        private String m_InvokeMethod;

        public String InvokObjectType { get { return m_InvokObjectType; } set { m_InvokObjectType = value; } }
        public String InvokObjectRef { get { return m_InvokObjectRef; } set { m_InvokObjectRef = value; } }
        public String InvokeMethod { get { return m_InvokeMethod; } set { m_InvokeMethod = value; } }

        /// <summary>
        /// 
        /// </summary>
        public InvokerActivity()
        { 
        }

        public override ITask CreateActivityInstance()
        {
            return new InvokerActivityInstance(this);
        }

        public override string ActivityType
        {
            get { return "Activity.InvokerActivity"; }
        }

        #region Serialize && Deserialize
        public override void SerializeConfiguration(System.Xml.XmlElement parent)
        {
            XmlElement XmlType = parent.OwnerDocument.CreateElement(Prop_InvokObjectType);
            XmlType.InnerText = this.InvokObjectType;
            parent.AppendChild(XmlType);

            XmlElement XmlObjectRef = parent.OwnerDocument.CreateElement(Prop_InvokObjectRef);
            XmlObjectRef.InnerText = this.InvokObjectRef;
            parent.AppendChild(XmlObjectRef);

            XmlElement XmlMethod = parent.OwnerDocument.CreateElement(Prop_InvokeMethod);
            XmlMethod.InnerText = this.InvokeMethod;
            parent.AppendChild(XmlMethod);
        }
        public override void DeserializeConfiguration(System.Xml.XmlElement parent)
        {
            XmlElement XmlType = parent.SelectSingleNode(Prop_InvokObjectType) as XmlElement;
            if (XmlType!=null)
                this.InvokObjectType = XmlType.InnerText;

            XmlElement XmlInvokObjectRef = parent.SelectSingleNode(Prop_InvokObjectRef) as XmlElement;
            if (XmlInvokObjectRef != null)
                this.InvokObjectRef = XmlInvokObjectRef.InnerText;

            XmlElement XmlInvokeMethod = parent.SelectSingleNode(Prop_InvokeMethod) as XmlElement;
            if (XmlInvokeMethod != null)
                this.InvokeMethod = XmlInvokeMethod.InnerText;
        }
        #endregion
    }
    
    public class InvokerActivityInstance : AbstractActivityInstance
    {
        public InvokerActivityInstance(InvokerActivity activity)
            : base(activity)
        {
        }
        public override bool Excute(IJobContext context)
        {
            throw new NotImplementedException();
        }
    }

}
